package com.exam.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.exam.entity.RespPageBean;
import com.exam.entity.Score;
import com.exam.service.IScoreService;
import com.exam.util.RespBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.xml.ws.Action;

/**
 * <p>
 * 成绩管理表 前端控制器
 * </p>
 *
 * @author zyh
 * @since 2023-03-09
 */
@RestController
@RequestMapping("/score")
public class ScoreController {

    @Autowired
    private IScoreService iScoreService;

    @PostMapping
    public RespBean add(@RequestBody Score score){
        iScoreService.save(score);
        return RespBean.success("提交成功！");
    }

    @GetMapping("/{page}/{size}/{studentId}")
    public RespBean list(@PathVariable("page") Integer page, @PathVariable("size") Integer size, @PathVariable("studentId") Integer studentId) {
        Page<Score> page1=new Page<>(page,size);
        LambdaQueryWrapper<Score> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(Score::getStudentId,studentId);
        iScoreService.page(page1,queryWrapper);
        RespPageBean respPageBean=new RespPageBean();
        respPageBean.setData(page1.getRecords());
        respPageBean.setTotal(page1.getTotal());
        return RespBean.success("操作成功！",respPageBean);
    }

}
